package Parentheses

func generateParenthesis(n int) []string {
	return recursion(0, 0, n, "", []string{})
}

func recursion(left, right, n int, str string, result []string) []string {
	if left == right && left == n {
		result = append(result, str)
		return result
	}
	if left < n {
		result = recursion(left+1, right, n, str+"(", result)
	}
	if right < left && right < n {
		result = recursion(left, right+1, n, str+")", result)
	}
	return result
}
